package com.example.dynamicschedule.utils;


import com.example.dynamicschedule.base.ResultCode;
import com.example.dynamicschedule.base.ResultDTO;

/**
 *返回信息工具
 */
public final class ResultUtils {
    private ResultUtils() {
    }

    public static ResultDTO getSuccess(Object result) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultCode.SUCCESS.getCode());
        resultDTO.setMsg(ResultCode.SUCCESS.getErrorDesc());
        resultDTO.setData(result);

        return resultDTO;
    }



    public static ResultDTO getFail(Object result) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultCode.FAIL.getCode());
        resultDTO.setMsg(ResultCode.FAIL.getErrorDesc());
        resultDTO.setData(result);
        return resultDTO;
    }

    public static ResultDTO getParamError(Object result)
    {   ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultCode.PARAM_ERROR.getCode());
        resultDTO.setMsg(ResultCode.PARAM_ERROR.getErrorDesc());
        resultDTO.setData(result);
        return resultDTO;
    }

    public static ResultDTO getResourceInvalid(Object result) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultCode.RESOURCE_INVALID.getCode());
        resultDTO.setMsg(ResultCode.RESOURCE_INVALID.getErrorDesc());
        resultDTO.setData(result);
        return resultDTO;
    }

    public static ResultDTO getTokenInvalid(Object result) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultCode.TOKEN_INVALID.getCode());
        resultDTO.setMsg(ResultCode.TOKEN_INVALID.getErrorDesc());
        resultDTO.setData(result);
        return resultDTO;
    }

    public static ResultDTO getCustomErrordesc(String errorDesc, Object result) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(ResultCode.CUSTOM_ERRORDESC.getCode());
        resultDTO.setMsg(ResultCode.CUSTOM_ERRORDESC.getErrorDesc());
        resultDTO.setData(result);
        return resultDTO;
}

    public static ResultDTO getResultDTO(int code, String errorDesc, Object result) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(code);
        resultDTO.setMsg(errorDesc);
        resultDTO.setData(result);
        return resultDTO;
    }
}
